package com.chen.permission.service.impl;

import com.chen.basic.service.impl.BaseServiceImpl;
import com.chen.permission.dto.RolePermissionDTO;
import com.chen.permission.query.RoleQuery;
import com.chen.permission.domain.Role;
import com.chen.permission.mapper.RoleMapper;
import com.chen.permission.service.IRoleService;
import com.chen.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

@Service
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public void deleteById(Serializable id) {
        // 删除角色的时候把角色的权限也删除
        roleMapper.deleteById(id);
        roleMapper.deleteByIdRolePermission((Long) id);
    }

    @Override
    public void saveRolePermission(RolePermissionDTO dto) {
        Long roleId = dto.getRoleId();
        // 先去根据id删除所有角色的权限信息
        roleMapper.deleteByIdRolePermission(roleId);
        System.out.println(roleId);
        System.out.println(dto.getPermissionSns());
        roleMapper.saveRolePermission(roleId,dto.getPermissionSns());
    }

    @Override
    public List<String> getByIdRolePermission(Long roleId) {
        return roleMapper.selectByIdRolePer(roleId);
    }
}
